package com.android.mios;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.android.mios.adapter.CurtainGridViewAdapter;
import com.android.mios.intenet.PollLoop;
import com.android.mios.model.Category;
import com.android.mios.model.Device;
import com.android.mios.util.Global;

import android.os.Bundle;
import android.widget.GridView;

public class CurtainControlActivity extends DeviceBaseActivity {

	private List<Device> curtainOfArray;
	private GridView mGridView;
	private CurtainGridViewAdapter mCurtainGridViewAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.curtain_contrl_layout);
		initData();
		initView();
	}

	private void initData() {

		curtainOfArray = new ArrayList<Device>();
		mCurtainGridViewAdapter = new CurtainGridViewAdapter(this,
				curtainOfArray, R.layout.curtain_dimmable_item);

	}

	private void initView() {

		initGridView();
	}

	private void initGridView() {

		mGridView = (GridView) findViewById(R.id.GV_LightControl);
		mGridView.setAdapter(mCurtainGridViewAdapter);

	}

	@Override
	protected List<Device> getDeviceList(int serialNumber,int roomId) {
		// TODO Auto-generated method stub
		Map<String, Device> allDevices = PollLoop.getInstance().getDevices();

		List<Device> devices = Device.findUnHideDevicesByCategory(allDevices,
				Category.WINDOW_COVERING);

		if (roomId != -1)// -1 is all room
			devices = Device.findDevicesByRoom(devices,serialNumber, roomId);

		return devices;
	}

	@Override
	protected void updateDevice() {
		// TODO Auto-generated method stub
		curtainOfArray.clear();
		curtainOfArray.addAll(getDeviceList(Global.getInstance().getSerialNumber(),Global.getInstance().getRoomID()));
		mCurtainGridViewAdapter.notifyDataSetChanged();
	}

}
